home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 6 / coreaids.zip / HEXDSPLY.ASM < prev    next >
Assembly Source File  |  1987-06-25  |  2KB  |  84 lines

  1. ;    DESC:    Displays hexadecimal codes as ASCII values           V1.00
  2. ;    IN:    *{HEX_WORD} hex word (0000 - FFFF)
  3. ;    OUT:    *{ASC_HI} first two characters of result (i.e EF from EFAB)
  4. ;        *{ASC_LO} second two characters of result (i.e. AB from EFAB)
  5. ;    SAMPLE:    Callm    HEXDSPLY,<HEX_WORD>,<ASC_HI,ASC_LO>
  6. ;    ##################################################################
  7.  
  8.     Extrn    PUSHALL:Near
  9.     Extrn    POPALL:Near
  10.  
  11. HEXDSPLC    Segment
  12.     Assume    CS:HEXDSPLC
  13.     Public    HEXDSPLY
  14.  
  15.                         ;notice.
  16.     DB    'HEXDSPLY - V1.00, Copyright 1987, CoreTechs   ',0DH,0AH
  17.  
  18. HEXDSPLY    Proc    Near
  19.     Call    PUSHALL                ;save registers.
  20.  
  21.     Pop    DX                ;recover hex word.
  22.  
  23.     Mov    AX,0F000H            ;mask out 4th nibble.
  24.     And    AX,DX
  25.     Mov    BH,AH
  26.     Mov    CL,4
  27.     Shr    BH,CL                ;store in BH.
  28.  
  29.     Mov    AX,00F0H            ;mask out 2nd nibble.
  30.     And    AX,DX
  31.     Mov    CH,AL
  32.     Mov    CL,4
  33.     Shr    CH,CL                ;save permanent in CH.
  34.  
  35.     Mov    AX,0F00H            ;mask out 3rd nibble.
  36.     And    AX,DX
  37.     Mov    BL,AH                ;store in BH.
  38.  
  39.     Mov    AX,000FH            ;mask out 1st nibble.
  40.     And    AX,DX
  41.     Mov    CL,AL                ;store in CL.
  42.  
  43.     Cmp    BH,9                ;determine if hex digit is
  44.     Ja    BH1                ;in 0-9 range.
  45.  
  46.     Add    BH,30H                ;if not, add to make ASCII.
  47.     Jmp    BL1
  48.  
  49. BH1:    Add    BH,37H                ;add to make letter.
  50.  
  51. BL1:    Cmp    BL,9                ;determine if hex digit is
  52.     Ja    BL2                ;in 0-9 range.
  53.  
  54.     Add    BL,30H                ;if not, add to make ASCII.
  55.     Jmp    CH1
  56.  
  57. BL2:    Add    BL,37H                ;add to make letter.
  58.  
  59. CH1:    Cmp    CH,9                ;determine if hex digit is
  60.     Ja    CH2                ;in 0-9 range.
  61.  
  62.     Add    CH,30H                ;if not, add to make ASCII.
  63.     Jmp    CL1
  64.  
  65. CH2:    Add    CH,37H                ;add to make letter.
  66.  
  67. CL1:    Cmp    CL,9                ;determine if hex digit is
  68.     Ja    CL2                ;in 0-9 range.
  69.  
  70.     Add    CL,30H                ;if not, add to make ASCII.
  71.     Jmp    DONE
  72.  
  73. CL2:    Add    CL,37H                ;add to make letter.
  74.  
  75. DONE:    Push    CX                ;return hex in ASCII format.
  76.     Push    BX
  77.  
  78.     Call    POPALL                ;recover registers.
  79.     Ret
  80.  
  81. HEXDSPLY    Endp
  82. HEXDSPLC    Ends
  83.     End
  84.